const webviewId = 'notifyView'
let timer = 0
let notifyView = null
const Notify = function({
	time = 3000,
	message = '',
	cb
}) {
	console.log(message)
	notifyView = null
	clearTimeout(timer)
	notifyView = document.getElementById(webviewId)
	if (!notifyView) {
		let $div = document.createElement('div')
		$div.innerHTML = `<div id="${webviewId}" style="
			position: fixed; 
			top: 0; 
			left: 0; 
			width: 100%;
			color: #Fff; 
			display: none; 
			z-index: 9999999; 
			height: ${uni.upx2px(176)}px; 
			line-height: ${uni.upx2px(176)}px;
			font-size: ${uni.upx2px(36)}px;
			background: rgba(14, 9, 1, 1);">
				<div style="
					display: flex;
					align-items: center;">
					<image src="${message.avatar}"
						style="
						margin: 0 ${uni.upx2px(40)}px 0 ${uni.upx2px(40)}px;
						width: ${uni.upx2px(100)}px;
						height: ${uni.upx2px(100)}px;
						border-radius:50%;
					"></image>
					<span style="
						font-family: PingFang SC-Regular, PingFang SC;
						color: #FF7C1F;
					">${message.username}</span>
				</div>
			</div>`
		notifyView = $div.firstChild
		document.body.appendChild(notifyView)
		notifyView.addEventListener("click", () => {
			notifyView.style.display = 'none'
			cb && cb({
				type: "click",
				result: message
			});
		});
	}

	notifyView.style.display = 'block'
	timer = setTimeout(() => {
		notifyView.style.display = 'none'
	}, time);
}

export default Notify